package org.lanqiao.controller.report;

import com.alibaba.dubbo.config.annotation.Reference;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.lanqiao.config.entity.ResponseData;
import org.lanqiao.information.IInfoService;
import org.lanqiao.information.Information;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("report")
@Api(tags = "资源举报模块Report")
public class ReportController {
    @Reference
    private IInfoService iInfoService;
    @GetMapping("/InforListByReport")
    @ApiOperation(value = "被举报的资源",notes = "获取所有被举报的资源")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "第一级分类",name = "sort1id",required = false,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(value = "第二级分类",name = "sort2id",required = false,dataType = "Integer",paramType = "query")
    })
    public ResponseData<Information> InforListByReport(@RequestParam Integer sort1id, @RequestParam Integer sort2id){
        List<Information> infoList =  iInfoService.InfoListByReport(sort1id, sort2id);
        if(infoList!= null){
            return  ResponseData.success().putDataVule("infoList",infoList);
        }else{
            return ResponseData.serverInternalError();
        }
    }
    @GetMapping("/InfoReport")
    @ApiOperation(value = "举报资源",notes = "举报资源传入 infoid tipuserid tipcontent")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "资源id",name = "infoid",required = true,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(value = "举报者id",name = "tipuserid",required = false,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(value = "举报内容",name = "tipcontent",required = false,dataType = "String",paramType = "query")
    })
    public ResponseData<Information> InfoReport(Integer infoid, Integer tipuserid, String tipcontent){
        Integer result = iInfoService.InfoReport(infoid, tipuserid, tipcontent);
        if(result!= null){
            return  ResponseData.success().putDataVule("result",result);
        }else{
            return ResponseData.serverInternalError();
        }
    }
    @GetMapping("/ReportSuccess")
    @ApiOperation(value = "举报成功",notes = "举报成功将资源的状态改为4")
    @ApiImplicitParam(value = "资源id",name = "id",required = true,dataType = "Integer",paramType = "query")
    public ResponseData<Information> ReportSuccess(Integer id){
        Integer result = iInfoService.ReportSuccess(id);
        if(result!= null){
            return  ResponseData.success().putDataVule("result",result);
        }else{
            return ResponseData.serverInternalError();
        }
    }
    @GetMapping("/ReportFail")
    @ApiOperation(value = "举报失败",notes = "举报失败将资源的状态改回1")
    @ApiImplicitParam(value = "资源id",name = "id",required = true,dataType = "Integer",paramType = "query")
    public ResponseData<Information> ReportFail(Integer id){
        Integer result = iInfoService.ReportFail(id);
        if(result!= null){
            return  ResponseData.success().putDataVule("result",result);
        }else{
            return ResponseData.serverInternalError();
        }
    }
}
